package com.lagou.rabbitmq.demo.delayedpay.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MyCancelListener implements ChannelAwareMessageListener {

    @RabbitListener(queues = "q.dlx", ackMode = "MANUAL")
    public void onMessage(Message message, Channel channel) throws IOException {
        System.out.println("---->接收延迟等待消息");
        // 查询订单消息
        // 1.订单已支付，那么不需要改动
        // 2.订单未支付，那么取消订单

        String orderId = new String(message.getBody());
        System.out.println("取消订单：" + orderId);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
